package com.liy.supercloud.ssoserver.config;

import com.liy.framework.common.extvo.LoginInfo;
import com.liy.framework.common.jwt.JWTHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class JwtTokenSevice {

    @Value("${dascloud.authrization.token.expire}")
    private int expire;

    @Autowired
    private AuthKeyConfig keyConfig;


    public String generateToken(LoginInfo loginUser) throws Exception {
        return JWTHelper.generateToken(loginUser, this.keyConfig.getUserPriKey(), this.expire);
    }

    public LoginInfo getInfoFromToken(String token) throws Exception {
        return JWTHelper.getInfoFromToken(token, this.keyConfig.getUserPubKey());
    }
}
